import { effect } from '@preact/signals-core';
import mixinValue from '../../mixins/value';
import { ComponentWithSignalStoreImpl, triggerEvent } from '../../_util/simply';
import i18nController from '../../_util/store';
import { TextareaDefaultProps } from './props';
ComponentWithSignalStoreImpl({
    storeOptions: {
        store: function () { return i18nController; },
        updateHook: effect,
        mapState: {
            locale: function (_a) {
                var store = _a.store;
                return store.currentLocale.value;
            },
        },
    },
    props: TextareaDefaultProps,
    data: {
        selfFocus: false,
    },
    methods: {
        onChange: function (e) {
            var value = e.detail.value;
            if (!this.isControlled()) {
                this.update(value);
            }
            triggerEvent(this, 'change', value, e);
        },
        onFocus: function (e) {
            var value = e.detail.value;
            this.setData({
                selfFocus: true,
            });
            triggerEvent(this, 'focus', value, e);
        },
        onBlur: function (e) {
            var value = e.detail.value;
            this.setData({
                selfFocus: false,
            });
            triggerEvent(this, 'blur', value, e);
        },
        onConfirm: function (e) {
            var value = e.detail.value;
            triggerEvent(this, 'confirm', value, e);
        },
        onClear: function (e) {
            if (!this.isControlled()) {
                this.update('');
            }
            triggerEvent(this, 'change', '', e);
        },
    },
    mixins: [mixinValue({ scopeKey: 'state' })],
    attached: function () {
        this.triggerEvent('ref', this);
    },
});
